Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: implement the placement rules inheritance logic #28365

Merged
merged 29 commits into from
Oct 8, 2021

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Sep 26, 2021

Signed-off-by: ailinkid 314806019@qq.com

What problem does this PR solve?

Issue Number: close #28364

What is changed and how it works?

How it Works:
avoid to write the default placement bundle to pd again when creating table

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
tiup playground nightly --tiflash 0  --db 2 --db.binpath  ~/go/src/github.com/pingcap/tidb/bin/tidb-server
http://127.0.0.1:2379/pd/api/v1/config/placement-rule  // check the placement must only one ------ PD default rules
create table t(a int) constraints="[-region=ssd]";           // create a test table with direct policy
http://127.0.0.1:2379/pd/api/v1/config/placement-rule  // check the placement rules again  ------ PD default + Table specified
check the rule for `index` and `override` field, it must be the `IndexTable` and `True`

Inaddition:
placement-rules-inheritance-test

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 26, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lcwangchao
  • xhebox

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 26, 2021
@AilinKid AilinKid force-pushed the avoid-sync-default-bundle-to-pd branch from a4b412d to 914db2d Compare September 26, 2021 11:10
Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense that we have a function like Bundle.SetType(db | tbl). But that can be done later.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 27, 2021
@xhebox xhebox requested a review from morgo September 27, 2021 01:13
ddl/table.go Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
@AilinKid AilinKid removed the status/LGT1 Indicates that a PR has LGTM 1. label Sep 28, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 28, 2021
@AilinKid
Copy link
Contributor Author

/run-check_dev

ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please:

  1. Refactor Reset(index, ids...int64), remove/integrate Append and xxxBundleWrapper within it. For simplicity, better keep only one reset function.
  2. Remove all bundle.Tidy(), move them into infosync.PutRuleBundles.
  3. Remove checkPolicyValidation here, it is duplicated because of NewBundleFromOptions.

The code will be much simpler with above changes.

ddl/placement/bundle.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Show resolved Hide resolved
ddl/table.go Outdated
Comment on lines 199 to 180
err = bundle.Tidy()
if err != nil {
return nil, errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reset first, then Tidy. Maybe we could move all Tidy to infosync.PutRuleBundles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy first is reasonable. Since tidy wanna append a NotIn TiFlash rule, it should be done before reset work.
The later will clone all these rule for other new ids. otherwise, we should append NotIn TiFlash rule for every independent id inferred from startKey/ EndKey

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy was intended to be used as an post-optimization. Maybe we should move the append of -engine=tiflash into reset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it into the new bundle portal function --- NewBundleFromOptions, which are much more clear.

ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed status/LGT1 Indicates that a PR has LGTM 1. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 28, 2021
@AilinKid AilinKid changed the title ddl: use the persistent policy in parent objects and avoid use pd default bundle ddl: implement the placement rules inheritance logic Sep 29, 2021
@AilinKid
Copy link
Contributor Author

AilinKid commented Sep 30, 2021

placement-rules-inheritance-test.md

here is the manual test script and test results

@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 30, 2021
rule.GroupID = b.ID
rule.StartKeyHex = startKey
rule.EndKeyHex = endKey
func (b *Bundle) Reset(ruleIndex int, newIDs []int64) *Bundle {
Copy link
Collaborator

@lcwangchao lcwangchao Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code about bundles seems some what weird and a little complex now. How about refactoring them to below methods:

// Build bundle from table info, and the partition rules and included in the return
NewBundleFromTable(tbl *model.TableInfo) (*Bundle, error)

// Build bundle from partition
NewBundleFromPartition(partition *model.PartitionDefinition) (*Bundle, error)

I think the above methods is enough for ddl to use. It's not necessary to use BundleByName in infoschema because we'll finally delete it and the logic that directly building bundle from meta is more brief and easy to maintain.

We do not need method Tidy too. We can tidy the bundle when we constructing it, I think no where requires a not tidied bundle.

Another advices is the reuse of the code, for example, we can introduce a private method like

newBundleFromPolicyOrDirectOptions(infoschema.InfoSchema, *model.PolicyRefInfo, *model.PlacementSettings) (*Bundle, error)

It will return a semi-finished Bundle and just for code reuse and it should only be visible in placement package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1: refactored to func NewBundleFromTblInfo(t *meta.Meta, job *model.Job, tbInfo *model.TableInfo) and func NewBundleFromPartition(t *meta.Meta, job *model.Job, partition *model.PartitionInfo)
2: tidy moved to constructors--- NewBundleFromOptions
3: the newBundleFromPolicyOrDirectOptions function is built

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AilinKid, where is the change of 2? I don't see that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added, missed in my commits

@AilinKid AilinKid force-pushed the avoid-sync-default-bundle-to-pd branch from 7eec66d to 3c72015 Compare October 2, 2021 00:58
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 2, 2021
@morgo morgo requested a review from xhebox October 6, 2021 19:28
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 8, 2021
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
.
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
@AilinKid AilinKid force-pushed the avoid-sync-default-bundle-to-pd branch from 08d26e7 to 247a8df Compare October 8, 2021 06:51
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 8, 2021
Signed-off-by: ailinkid <314806019@qq.com>
@AilinKid AilinKid force-pushed the avoid-sync-default-bundle-to-pd branch from 173a4d0 to ad907f3 Compare October 8, 2021 07:02
@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 8, 2021
@AilinKid
Copy link
Contributor Author

AilinKid commented Oct 8, 2021

/run-check_dev_2

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 8, 2021
@xhebox
Copy link
Contributor

xhebox commented Oct 8, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 6806823

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 8, 2021
@ti-chi-bot ti-chi-bot merged commit b63bc2b into pingcap:master Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ddl will write the default pd policy bundle again
4 participants